dayOffset <- function(TS) {
  XTS <- eval(TS[,1]>0)  # forms a dummy xts object with TRUE in first column
  DAY <- cbind(XTS, .indexday(TS))
  DAY1 <- lag(DAY[,2], k=(-1))-DAY[,2]
  DAY2 <- lag(DAY[,2], k=(-2))-DAY[,2]
  DAY3 <- lag(DAY[,2], k=(-3))-DAY[,2]
  DAY4 <- lag(DAY[,2], k=(-4))-DAY[,2]
  DAY5 <- lag(DAY[,2], k=(-5))-DAY[,2]
  result<-(DAY1+DAY2+DAY3+DAY4+DAY5)
  return(result)
}

